package game.ability;

import java.util.Random;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

import game.entity.AbsSprite;
import game.entity.SpriteManager;
import game.particles.AbsParticle;
import game.particles.Particle_1;
import game.shared.Constants;

public class SnowDown  extends AbsAbility{

	float slower;
	float oldSpeed;
	boolean bFlag = false, finish=false;
	AbsSprite snow;
	SpriteManager snowManager;
	Random random;
	float timer;
	float duration;
	float curSlower;
    AbsParticle particle_1;

	@Override
	public void action() {
		timer = 0;
	}
	
	public SnowDown(float slower, float duration) {
		super();
		this.duration = duration;
		this.slower = slower;
		this.timer = duration + 1;
		//createSnowImage();
		particle_1 = new Particle_1("res/particles/particle_rain", "res/particles");
		particle_1.setPosition(-100, Gdx.graphics.getHeight());
	}
/*
	private void createSnowImage() {
		snowManager = new SpriteManager();
		random = new Random();
		AbsSprite snow = new AbsSprite(snowManager, "res/img/snow.txt");
		snow.setMoving(new MovingSnowDown(1.5f));
		snow.setPosition(80+random.nextInt(400), random.nextInt(320+random.nextInt(320)));
		snowManager.add(snow);
		for(int i=1; i<50; i++)
		{
			snowManager.add(new AbsSprite(snow));
			snow.setMoving(new MovingSnowDown(5+random.nextInt(4)));
			snowManager.getByIndex(i).setPosition(80+random.nextInt(400), random.nextInt(320+random.nextInt(320)));
		}
	}
	*/
	@Override
	public void update() {
		timer += Gdx.graphics.getDeltaTime();
		
		curSlower = timer < duration ? slower : 1;		
		for(int i=0; i<targetSprites.count(); i++)
			targetSprites.getByIndex(i).setSlower(curSlower);
		
		//snowManager.update();
	}
	
	@Override
	public void render(SpriteBatch sb) 
	{
		if(timer > duration)
			return;
		//snowManager.render(sb);
		particle_1.render(sb);
	}
}
